from app.db.session import SessionLocal
from app.models.user import User
from app.utils.hashing import get_password_hash

def init_db():
    db = SessionLocal()

    # 检查是否存在 admin 用户
    admin_user = db.query(User).filter(User.username == "wtkjadmin").first()
    if not admin_user:
        # 创建 admin 用户
        admin_user = User(
            username="wtkjadmin",
            chinese_name="管理员",
            password_hash=get_password_hash("Wtkj@2332"),  # 初始密码
            source=0,
            department="IT",
            position="系统管理员",
            phone="1234567890",
            is_admin=True
        )
        db.add(admin_user)
        db.commit()
        print("初始 admin 用户已创建。")
    else:
        print("admin 用户已存在。")

    db.close()